package com.itany.shop.service.proxy;

import com.itany.shop.entity.Product;
import com.itany.shop.factory.ObjectFactory;
import com.itany.shop.service.ProductService;
import com.itany.shop.tran.TransactionManager;

import java.util.List;

/**
 * @Author:石小俊
 * @Date:2022/12/16 9:40
 * @Version:1.0-SNAPSHOT
 * @Description:
 */
public class ProductServiceProxy implements ProductService {

    private TransactionManager tran = (TransactionManager) ObjectFactory.getObject("tran");
    private ProductService productService = (ProductService) ObjectFactory.getObject("productServiceTarget");

    @Override
    public List<Product> findAll() {
        try {
            tran.begin();
            List<Product> products = productService.findAll();
            tran.commit();
            return products;
        } catch (Exception e) {
            tran.rollback();
            throw e;
        }
    }
}
